package com.csap.framework.oauth2.client;

import com.csap.framework.annotation.ResponseAdvice;
import com.csap.framework.annotation.apidoc.Api;
import com.csap.framework.annotation.apidoc.ApiOperation;
import com.csap.framework.extension.result.ResultParam;
import com.csap.framework.oauth2.client.rest.Oauth2ClientApi;
import com.csap.framework.oauth2.open.RoleOpenApi;
import com.csap.framework.oauth2.request.RolesRequest;
import com.csap.framework.oauth2.request.RolesResponse;
import com.csap.framework.oauth2.request.UserPermissionsVo;
import com.csap.framework.oauth2.request.UserRolesRequest;
import com.csap.mybatisplus.page.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;

/**
 * 客户端接口
 *
 * @author yangchengfu
 * @dataTime 2021年-07月-29日 16:47:00
 **/
@RestController
@ResponseAdvice
@RequestMapping("oauth2")
@Api(value = "客服端-授权认证")
@Slf4j
@AllArgsConstructor
public class Oauth2RestEndpoint implements RoleOpenApi {
    /**
     * 客户端API
     */
    private Oauth2ClientApi oauth2ClientApiRest;

    @ApiOperation("添加角色")
    @Override
    public ResultParam<Long> addRole(RolesRequest rolesModel) {
        return oauth2ClientApiRest.addRole(rolesModel);
    }

    @ApiOperation("修改角色")
    @Override
    public ResultParam<Boolean> updateRole(RolesRequest rolesModel) {
        return oauth2ClientApiRest.updateRole(rolesModel);
    }

    @ApiOperation("删除角色")
    @Override
    public ResultParam<Boolean> remove(Long id) {
        return oauth2ClientApiRest.remove(id);
    }

    @ApiOperation("分页查询角色")
    @Override
    public ResultParam<Page<RolesResponse>> queryPage(RolesRequest rolesModel) {
        return oauth2ClientApiRest.queryPage(rolesModel);
    }

    @ApiOperation("添加或者修改用户权限")
    @Override
    public ResultParam<Boolean> saveOrUpdateUserPermissions(UserPermissionsVo vo) {
        return oauth2ClientApiRest.saveOrUpdateUserPermissions(vo);
    }

    @ApiOperation("根据openId查询用户的角色ID")
    @Override
    public ResultParam<Set<Long>> queryUserRolesByOpenId(UserRolesRequest userRolesRequest) {
        return oauth2ClientApiRest.queryUserRolesByOpenId(userRolesRequest);
    }

    @ApiOperation("根据openId查询用户端角色名称")
    @Override
    public ResultParam<String> queryUserRoleNameByOpenId(UserRolesRequest userRolesRequest) {
        return oauth2ClientApiRest.queryUserRoleNameByOpenId(userRolesRequest);
    }

    @Override
    public ResultParam<Map<Long, RolesResponse>> findMapByIds(String ids) {
        return oauth2ClientApiRest.findMapByIds(ids);
    }

    @ApiOperation("添加/修改用户角色")
    @Override
    public ResultParam<Boolean> addUserRoles(UserRolesRequest userRolesRequest) {
        return oauth2ClientApiRest.addUserRoles(userRolesRequest);
    }
}
